﻿using System;
using System.Collections.Generic;
using System.IO.Ports;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace OrBitDataModule.CustomEventHandler
{
    /// <summary>
    /// 串口事件参数
    /// </summary>
    public class SerialPortReceivedEventArgs : EventArgs
    {
        /// <summary>
        /// 是否将接口返回的数据发送给设备
        /// </summary>
        public bool IsSend { get; set; } = true;
        public SerialPort SerialPort { get; }
        /// <summary>
        /// 端口名称
        /// </summary>
        public string PortName { get; }
        /// <summary>
        /// 波特率
        /// </summary>
        public int BaudRate { get; }
        /// <summary>
        /// 校验位
        /// </summary>
        public Parity Parity { get; }
        /// <summary>
        /// 数据位
        /// </summary>
        public int DataBits { get; }
        /// <summary>
        /// 停止位
        /// </summary>
        public StopBits StopBits { get; }
        /// <summary>
        /// 默认编码
        /// </summary>
        public Encoding DefaultEncoding { get; }
        /// <summary>
        /// 串口接收数据
        /// </summary>
        public byte[] Data { get; }

        /// <summary>
        /// ctor
        /// </summary>
        /// <param name="serialPort"></param>
        /// <param name="portName"></param>
        /// <param name="baudRate"></param>
        /// <param name="parity"></param>
        /// <param name="dataBits"></param>
        /// <param name="stopBits"></param>
        /// <param name="defaultEncoding"></param>
        /// <param name="data"></param>
        public SerialPortReceivedEventArgs(SerialPort serialPort, string portName, int baudRate, Parity parity, int dataBits, StopBits stopBits, Encoding defaultEncoding, byte[] data)
        {
            this.SerialPort = serialPort;
            this.PortName = portName;
            this.BaudRate = baudRate;
            this.Parity = parity;
            this.DataBits = dataBits;
            this.StopBits = stopBits;
            this.DefaultEncoding = defaultEncoding;
            this.Data = data;
        }
    }
}
